var assert     = require('assert'),
	utility    = require('system/utility'),
	Router     = require('../router');

var aComparer = function (x) { return x.a }
var router;

module.exports = {
	'Router' : {
		'Instantiate': function() {
			router = new Router();
			assert.ok(router);
		},
		'Add' : {
			'UniqueRoute': function() {
				var options = { path: 'test', fn: function(data) { } };
				var wasThere = router.find(options);
				router.add( options );
				var isThere = router.find(options);
				assert.ok(!wasThere, 'should not have been there');
				assert.ok(isThere, 'should be there');
			},
		},
		'Remove': {
			'UniqueRoute': function() {
				var options = { path: 'test' };
				var wasThere = router.find(options);
				router.remove(options);
				var isThere = router.find(options);
				assert.ok(wasThere, 'should have been there');
				assert.ok(!isThere, 'should not be there');
			}
		},
		'Execute': {
			'UniqueRoute': function(done) {
				var a=0, options = { path: 'test', fn: function(options) { a=options.data.a; if (options.callback) options.callback(options); } };
				router.add(options);
				assert.ok(router.find(options));
				utility.do(
					function() {
						router.execute({ path: 'test', data: {a:1}, callback: function(options) {
							assert.equal(a,1);
							a++;
							done();
						} });
					},
					function() {
						assert.equal(a,2);
					}
				);
			}
		}
	}
}